<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../icon/iconfont.css" />
    <style>
        header{
          background-color: #fff;
          width: 100%;
          position: fixed;
          padding: 1.6rem 0.8rem 0.5rem 0.8rem;
        }
        header span:nth-of-type(1){
          font-size: 1rem
        }
        header span:nth-of-type(2){
          font-size: 1rem;
        }
        .top {
            background-size: 100% 100%;
            background-repeat: no-repeat;
            height: 14rem;
            background-image: url("../../../image/img/member-top.jpg");
        }

        .top .info,
        .item,
        .flex-item {
            height: 64%;
            display: flex;
            justify-content: space-around;
            align-items: center;
            text-align: center;
        }

        .flex-item {
            justify-content: space-between !important;
        }

        .aubtn {
            padding: .1rem 1rem;
            background-color: #E4C493;
            border-radius: .2rem;
        }

        .title {
            text-align:left;
            color: #E4C493;
        }

        .Jnum,
        .Ynum {
            color: #FFF;
            padding: .2rem 0;
        }

        .todaytask {
            padding: 0 1rem;
        }

        .todaytask>div {
            padding: .5rem 0;
        }
        .active{
          background: #EEE;
        }
    </style>
</head>

<body>
    <header>
      <span class="iconfont icon-fanhui" onClick="api.closeWin()"></span>
      <span>我的会员</span>
    </header>
    <div class="myvip" style="padding-top: 3.6rem">
        <div class="top">
            <div class="info">
                <div style="text-align: center; font-size:.8rem">
                    <!-- <div class="title">积分：<label class="Jnum"></label></div> -->
                    <div class="Jnum"></div>
                    <div class="title" >积分</div>
                    <!-- <div class="title" style="position:relative;">余额：<label style="position:absolute;left:3em" class="Ynum"></label></div> -->
                </div>
                <div>
                    <div style="margin:2rem 0 0 1.5rem;">
                        <img id="active" style="width:5rem;height:5rem;border-radius: 50%;" alt="">
                        <div id="username" class="title" style="text-align:center"></div>
                    </div>
                </div>
                <div style="text-align: center; font-size:.8rem">
                    <div class="Ynum Totalnum"></div>
                    <div class="title">累计充值</div>
                </div>
            </div>
        </div>

        <!-- 今日任务 -->
        <div class="todaytask">
            <div>今日任务</div>
            <div class="flex-item">
                <div>签到</div>
                <div><label id="Signinnum" style="font-size:20px;">0</label><em style="font-size:12px;">&nbsp;(积分)</em></div>
                <button class="aubtn" id="Signin" style="width:3.5rem;text-align:center;padding:0"></button>
            </div>

            <div class="flex-item">
                <div>分享</div>
                <div><label id="shareWxnum" style="font-size:20px;">0</label><em style="font-size:12px;">&nbsp;(积分)</em></div>
                <button class="aubtn" id="shareWx" style="width:3.5rem;text-align:center;padding:0"></button>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript" src="../../../script/dns.js"></script>
<script type="text/javascript" src="../../../script/aui-toast.js"></script>
<script type="text/javascript" src="../../../lib/zepto.js"></script>
<script type="text/javascript">
    apiready = function() {};
    //会员信息查询
    $(document).ready(function(){
      console.log(localStorage.getItem('token'));
        getVipinfo();
    });
    var toast = new auiToast({
        })
    function getVipinfo () {
      $.ajax({
         url: dns + 'user/membercentre',
         type: 'GET',
         data: {},
         beforeSend: function(request) {
             request.setRequestHeader("token", localStorage.getItem('token'));
             },
         success: function (res) {
           //console.log(JSON.stringify(res));
           if(res.code == '20000'){
             $('.Jnum').html(res.data.user.integral); //积分
             $('.Ynum').html(res.data.user.balance);//余额
             $('.Totalnum').html(res.data.user.balance_total);//累计充值
             $('#username').html(res.data.user.nickname);//昵称
             $('#active').attr('src',res.data.user.avatar.filepath);//昵称
             if(res.data.check_in.status == '0'){
               $('#Signin').html('签到');
               $('#Signin').removeAttr("disabled");
             }else{
               $('#Signin').html('已签到');
               $('#Signinnum').html('+1');
               $('#Signin').addClass('active');
               $('#Signin').attr("disabled","true");
             };
              if(res.data.share.status == '0'){
                 $('#shareWx').html('分享');
              }else{
                 $('#shareWxnum').html('+1');
                  $('#shareWx').addClass('active');
                 $('#shareWx').html('已分享');
              }
           }
         },
        });
    };

    //签到
    $('#Signin').click(function(){
      $.ajax({
         url: dns + 'user/add/integral',
         type: 'GET',
         data: {'action':1},
         beforeSend: function(request) {
             request.setRequestHeader("token", localStorage.getItem('token'));
             },
         success: function (res) {
           console.log(JSON.stringify(res));
           if(res.code == '20000'){
             toast.success({
                  title:"签到成功!",
                  duration:1500
              });
              var jnum = $('.Jnum').html();
              jnum++;
              $('.Jnum').html(jnum)
             // 监听签到之后刷新个人中心
             api.sendEvent({
               name:"signin_reload"
             })
             $('#Signin').html('已签到');
             $('#Signinnum').html('+1');
             $('#Signin').addClass('active');
             $('#Signin').attr("disabled","true");
           }
         },
        });
    });

    //分享
    $('#shareWx').click(function(){
      var wx = api.require('wx');
        wx.isInstalled(function(ret, err) {
        if (ret.installed) {
          wx.shareImage({
              apiKey: 'wx99475b10511a3195',
              scene: 'timeline',
              thumb: './codenew3.png',
              contentUrl: './codenew.jpg'
              }, function(ret, err) {
                  if (ret.status) {
                    $.ajax({
                       url: dns + 'user/add/integral',
                       type: 'GET',
                       data: {'action':2},
                       beforeSend: function(request) {
                           request.setRequestHeader("token", localStorage.getItem('token'));
                           },
                       success: function (res) {
                         if(res.code == '20000'){
                            $('#shareWxnum').html('+1');
                            $('#shareWx').html('已分享');
                             $('#shareWx').addClass('active');
                             $.ajax({
                                url: dns + 'user/membercentre',
                                type: 'GET',
                                data: {},
                                beforeSend: function(request) {
                                    request.setRequestHeader("token", localStorage.getItem('token'));
                                    },
                                success: function (res) {
                                  $('.Jnum').html(res.data.user.integral);
                                },
                               });
                           toast.success({
                                title:"分享成功!",
                                duration:1500
                            });
                            var jnum = $('.Jnum').html();
                            jnum++;
                            $('.Jnum').html(jnum)
                           // 监听分享之后刷新个人中心
                           api.sendEvent({
                             name:"signin_reload"
                           })
                         }
                       },
                      });
                  } else {
                    return;
                  }
              });
          } else {
            toast.fail({
                title:"当前设备未安装微信客户端!",
                duration:1500
            });
          }
        });
    });
</script>

</html>
